package com.test.controller.api;

import com.test.entity.AuthUser;
import com.test.service.BookService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.annotation.Resource;

@Controller
@RequestMapping("/api/user")
public class UserApiController {
    @Resource
    BookService bookService;
    @RequestMapping("/borrow-book")
    public String borrow_book(@RequestParam("id")int id, @SessionAttribute("user") AuthUser user){
        bookService.borrowBook(id,user.getId());
       return "redirect:/page/user/index";
    }
    @RequestMapping("/return-book")
    public String return_book(@RequestParam("id")int bid,@SessionAttribute("user") AuthUser user){
        bookService.returnBook(bid,user.getId());
        return "redirect:/page/user/book";
    }
}
